<?php
/**
 * Created by PhpStorm.
 * User: yejia
 * Date: 2016/8/13
 * Time: 14:21
 */

namespace Admin\Controller;

use Think\Controller;
class FeedbackController extends Controller
{
    public function index(){
        $id=session('id');
        $adminmodel=M('admin');
        $admin=$adminmodel->where(array('id'=>$id))->select();
        $this->admin=$admin;

        $feedbackmodel=M('fankui');
        $feedback=$feedbackmodel->order('id ')->select();
        $this->feedback=$feedback;
        for ($i = 0; $i < count($feedback); $i++){
            $feedback[$i]["code"] = $i + 1;
        }
        if(!$id)
        {$this->error('登录已过期!',U("index.php/Admin/Index/index"));}
        elseif($feedback){
            $this->assign('list', $feedback);
            $this->display();
        }
        elseif ($admin){
            $this->assign('admin', $admin);
            $this->display();
        }
        else{ $this->error('获取失败!', U("Admin/Feedback/index"));}
    }

public function del(){
    $id = $_GET['id'];
    $feedback = M("fankui");
    $feedback->id = $id;
    $feedback->delete();
    if ($feedback) {
        $this->success('删除成功');
    } else {
        $this->error('删除失败!');

    }
}


    public function search(){
        $username = trim(I('post.username'));
        $usersmodel=M('fankui');
        $a['username']=array('like',"%{$username}%");
        $select=$usersmodel->where($a)->select();

        for ($i = 0; $i < count($select); $i++){
            $select[$i]["code"] = $i + 1;
        }
        if($select)
        {
            $this->assign('list', $select);
            $this->display();
        }
        else{ $this->error('未查到相关结果,请重新查询',U("Feedback/index"));}


    }


}